package ThreadDemo1;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 故我
 * Date: 2023-10-10
 * Time: 18:16
 */
//阻塞队列的使用
public class ThreadDemo20 {
    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<String> blockingQueue = new LinkedBlockingQueue<>();
        blockingQueue.put("hello");//put是阻塞式入队列
        String res = blockingQueue.take();
        System.out.println(res);
        res = blockingQueue.take();//没有数据时，会阻塞在这里
        System.out.println(res);
    }
}
